<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改MYSQL密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__STATIC__/admin/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="__STATIC__/admin/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
    <!--百度-->
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">MYSQL用户名</label>
        <div class="layui-input-inline">
            <input type="text" id="username" lay-verify="required" lay-reqtext="FPT账号不能为空" placeholder="" value="{$data.username}" class="layui-input" style="width:180px;" readonly="readonly" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">MYSQL密码</label>
        <div class="layui-input-inline">
            <input type="text" name="password" id="password" lay-verify="required" lay-reqtext="FTP密码不能为空" placeholder="" value="{$data.password}" class="layui-input" style="width:180px;" readonly="readonly">
        </div>
        <div class="layui-form-mid layui-word-aux"><i onclick="shuaxin_password()" class="layui-icon layui-icon-refresh"></i></div>
        
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button  class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">提交修改</button>
        </div>
    </div>
</div>
<script src="__STATIC__/admin/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var name = document.getElementById("username").value;
            var password = document.getElementById("password").value;
            if(!password || password==''){
                layer.msg('请输入密码',{icon:2});
                return;
            }
            
            $.post('/add_passwordMysql',{'name':name,'password':password,'mysql_id':{$data.mysql_id}},function(res){
                if(res.code>0){
                  layer.msg(res.msg,{icon:2});  
                }else{
                  layer.msg(res.msg,{icon:1});
                }
            },'json');
        });

    });
    
    function shuaxin_password(){
        var password = randomString(16);
        document.getElementById("password").value=password;
    }
    
    function randomString(len) {
        　　len = len || 32;
        　　var $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
        　　var maxPos = $chars.length;
        　　var pwd = '';
        　　for (i = 0; i < len; i++) {
        		//0~32的整数
        　　　　pwd += $chars.charAt(Math.floor(Math.random() * (maxPos+1)));
        　　}
        　　return pwd;
    }

    
</script>
</body>